import time

import allure
from selenium.webdriver.common.by import By

from cloud_po.pages.base_page import BasePage


class WareHouseAddPage(BasePage):
    __INPUT_WNAME = (By.XPATH, "(//*[@class='el-input__inner'])[1]")
    __INPUT_WTIME = (By.XPATH, "(//*[@class='el-input__inner'])[3]")
    __INPUT_WTEAM = (By.XPATH, "(//*[@class='el-input__inner'])[8]")
    __INPUT_WWECHAT = (By.XPATH, "(//*[@class='el-input__inner'])[9]")
    __SAVE_BTN = (By.XPATH, "//span[text()='提交']")

    def add_warehouse(self,warehouse_name):
        """添加微信类型的仓库"""
        with allure.step("填写仓库表单"):
            time.sleep(2)
            self.do_send_keys(warehouse_name,self.__INPUT_WNAME)

            # 尝试多次点击
            self.safe_click(self.__INPUT_WTIME)
            time_confirm = self.web_locate_click((By.CSS_SELECTOR,".el-time-panel__btn.confirm"))
            time_confirm.click()

            self.do_find(self.__INPUT_WTEAM).click()
            # 下拉选滚轮滚到执行位置
            element = self.web_locate_click((By.XPATH,"//span[text()='仓库测试6群']"))
            self.driver.execute_script("arguments[0].scrollIntoView(true);", element)
            self.click_with_js((By.XPATH,"//span[text()='仓库测试6群']"))

            self.click_with_js(self.__INPUT_WWECHAT)
            # 微信取第一个
            self.do_find((By.CSS_SELECTOR,".el-select-dropdown__item.wx-receive")).click()
        with allure.step("点击提交"):
            self.do_find(self.__SAVE_BTN).click()
        from cloud_po.pages.warehouse_page import WareHousePage
        return  WareHousePage(self.driver)